/**
 * Created by KingKong on 2017/8/9.
 */
import {AbstractControl, ValidatorFn} from '@angular/forms';

/**
 * 自定义验证规则：最大长度
 * */
export function customizeMaxLengthValidator(length: number, key: string): ValidatorFn {
  return (control: AbstractControl): { [key: string]: any } => {
    let len = 0;
    if (!!control.value) {
      len = control.value.length;
    }
    return len <= length ? null : {[key]: true};
  };
}
